<template>
  <page-header-wrapper>
    <template v-slot:content> 所属项目：{{ $route.query.name }} </template>
    <a-card :bordered="false">
      <s-table
        ref="table"
        size="default"
        rowKey="ID"
        :columns="columns"
        :data="loadData"
        :pagination="{ showTotal: (total) => `共 ${total} 条` }"
      >
        <template #tabAction>
          <y-button type="primary" icon="plus" @click="handleAdd">添加进度</y-button>
        </template>
        <span slot="index" slot-scope="text, record, index">{{ index + 1 }} </span>
        <span slot="CreateDate" slot-scope="text">{{ text | moment('YYYY-MM-DD') }}</span>
        <div slot="action" slot-scope="text, record">
          <y-button type="link" @click="handleDetail(record)">查看进度</y-button>
          <y-button type="link" @click="handleEdit(record)" class="text-warning">修改</y-button>
        </div>
      </s-table>
    </a-card>
    <detail :visible.sync="visibleDetail" :data.sync="editData" />
    <scheduleForm :visible.sync="visibleForm" :data.sync="editData" @success="tableRefresh" />
  </page-header-wrapper>
</template>

<script>
import { STable, Ellipsis } from '@/components'
import detail from './components/schedule/detail.vue'
import scheduleForm from './components/schedule/form.vue'
import { getProjectScheduleList } from '@/api/followUpManagement'

export default {
  components: {
    STable,
    Ellipsis,
    detail,
    scheduleForm
  },
  data () {
    return {
      visibleDetail: false,
      visibleForm: false,
      editData: {},
      queryParam: {
        projectid: this.$route.params.id,
        Userid: this.$store.getters.userid
      },
      columns: [
        {
          title: '序号',
          align: 'center',
          width: '80px',
          scopedSlots: { customRender: 'index' }
        },
        {
          title: '创建时间',
          align: 'center',
          dataIndex: 'CreateDate',
          scopedSlots: { customRender: 'CreateDate' }
        },
        {
          title: '本月新开工数（套）',
          align: 'center',
          dataIndex: 'TMNewAmount'
        },
        {
          title: '本月新开工面积（㎡）',
          align: 'center',
          dataIndex: 'TMNewArea'
        },
        {
          title: '本月新竣工套数（套）',
          align: 'center',
          dataIndex: 'TMFulfilAmount'
        },
        {
          title: '本月新竣工面积（㎡）',
          align: 'center',
          dataIndex: 'TMFulfilArea'
        },
        {
          title: '累计开工套数（套）',
          align: 'center',
          dataIndex: 'TotalAmount'
        },
        {
          title: '累计开工面积（㎡）',
          align: 'center',
          dataIndex: 'TotalArea'
        },
        {
          title: '操作',
          align: 'center',
          width: '180px',
          scopedSlots: { customRender: 'action' }
        }
      ],
      // 加载数据方法 必须为 Promise 对象
      loadData: (parameter) => {
        const requestParameters = Object.assign({}, parameter, this.queryParam)
        return getProjectScheduleList(requestParameters).then((res) => res)
      }
    }
  },
  methods: {
    tableRefresh (refresh = false) {
      this.$refs.table.refresh(refresh)
    },
    handleDetail (record) {
      this.editData = record
      this.visibleDetail = true
    },
    handleEdit (record) {
      this.editData = record
      this.visibleForm = true
    },
    handleAdd () {
      this.editData = {}
      this.visibleForm = true
    }
  }
}
</script>
<style scoped>
</style>
